<%@page import="java.io.File"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script type="text/javascript">
	function downloadFile1(filenames, filepaths) {
		location.href = encodeURI("download.action?filenames=" + filenames
				+ "&filepaths=" + filepaths, "utf-8");
	}
	function SelectAll(oForm) {
		for ( var i = 0; i < oForm.url.length; i++) {
			oForm.url[i].checked = true;
		}
	}
	function TurnOver(oForm) {
		for ( var i = 0; i < oForm.url.length; i++) {
			oForm.url[i].checked = !oForm.url[i].checked;
		}
	}
	function DownlodSelected(oForm) {
		if (confirm("因需要在服务端动态打包,需要时间比较长,是否继续批量下载?")) {
			var arrDownloadList = [];
			for ( var i = 0; i < oForm.url.length; i++) {
				if (oForm.url[i].checked == true) {
					if (arrDownloadList.length == 0) {
						arrDownloadList[0] = oForm.url.value;
					}
					arrDownloadList[arrDownloadList.length] = oForm.url[i].value;
				}
			}
			if (arrDownloadList.length > 0) {
				var temp = [];
				var filenames = "";
				var filepaths = "";
				for ( var i = 1; i < arrDownloadList.length; i++) {
					temp = arrDownloadList[i].split(",")
					if (filenames == "" && filepaths == "") {
						filenames = temp[0]
						filepaths = temp[1]
					} else {
						filenames = filenames + "|" + temp[0];
						filepaths = filepaths + "|" + temp[1];
					}
				}
				downloadFile1(filenames, filepaths);
			} else {
				alert("还没有选中下载项");
			}
		}
	}
</script>
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'downloadList.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="css/style.css">

</head>
<body>
<%try {
			String tempfilePath = session.getAttribute("tempfilePath")
					.toString();
			System.err.println("*******"+tempfilePath);
			if (tempfilePath != null) {
				File tempfile = new File(tempfilePath);
				if (tempfile.exists()) {
					tempfile.delete();
					if (tempfile.exists()) {
						System.out.println("------删除临时文件失败-------");
					} else {
						System.out.println("------删除打包产生的临时文件------");
					}
				}
			}
		} catch (Exception e) {
		} %>
	<form name="myform" style="display: inline;">
		<table width="50%" align="center">
			<tr>
				<th colspan="2">以下是下载列表,点击进行下载
				</th>
				<th>操作</th>
			</tr>
			<% String rRootPath = request.getAttribute("fRootPath").toString();
			%>
			<s:iterator value="#request.fileMap" status="stuts">
			
					<tr>
						<td><input name="url" type="checkbox" id="url"
							value="<s:property value="key" />,<s:property value="value" />">
						</td>
						<td>
						  <s:property value="key" /> 
						<%-- <img src="<%=rRootPath%><s:property value="key" />" width="400xp;" height="400xp;"> --%>
						</td>
						<td><input type ="button" value="点击下载" 
							onclick="downloadFile1('<s:property value="key" />','<s:property value="value" />')" />
						</td>
					</tr>
			</s:iterator>
		</table>
		<div align="center">
			<input class="green_at_bn" title="选择下载的文件"
				onClick="SelectAll(this.form)" type="button" value="全选"> <input
				class="green_at_bn" title="反向选择下载文件" onClick="TurnOver(this.form)"
				type="button" value="反选"> <input class="green_at_bn"
				title="下载选中文件" onClick="DownlodSelected(this.form)" type="button"
				value="批量下载文件">
		</div>
	</form>
</body>

</html>
